package main

import (
	"database/sql"
	"fmt"
	"log"
	_ "github.com/go-sql-driver/mysql"
)

func main() {
	db, err := sql.Open(
		"mysql",
		"root:root@tcp(172.20.0.10:3306)/gogogo?charset=utf8",
	)
	if err != nil {
		log.Fatal("open db error.", err)
		return
	}
	defer db.Close()
	stmt, err := db.Prepare("INSERT INTO tbl_student (stu_no, name) VALUES (?, ?)")
	if err != nil {
		log.Fatal(err)
	}
	res, err := stmt.Exec("20200020001", "张小一")
	if err != nil {
		log.Fatal(err)
	}
	id, _ := res.LastInsertId()
	rowsAffected, _ := res.RowsAffected()
	fmt.Printf("id=%d, rowsAffected=%d\n", id, rowsAffected)

}
